package com.job.dao.Impl;

import com.job.dao.EmployerDao;
import com.job.model.Employer;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.management.Query;
import java.util.List;

/**
 * hibernate 实现
 * @author hasee
 */
@Repository("employerDao")
public class EmployerDaoImpl implements EmployerDao {

   private  SessionFactory sessionFactory;

    /**
     * 分页获取公司
     *
     * @param limitStart 分页开始
     * @param limitEnd   分页结束
     * @return 返回公司对象列表 为空则返回null
     */
    @Override
    public List<Employer> getEmployer(int limitStart, int limitEnd) {
       Session session= sessionFactory.openSession();
        org.hibernate.query.Query query=session.createQuery("from Employer ");
        query.setMaxResults(limitEnd-limitStart);
        query.setFirstResult(limitStart);
       List<Employer> list=  query.list();
       return list;
    }

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }
}
